﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using FTBS.Models.DAO;
using FTBS.Models.Entities;
using FTBS.Models.Entities.Concert;

namespace FTBS.Models.BLO
{
    public class FilmBLO
    {
        private FilmDAO _filmDao = new FilmDAO();

        /// <summary>
        /// load films
        /// </summary>
        /// <returns>list of film</returns>
        /// <author>hungph</author>
        public List<Film> LoadFilms()
        {
            var listFilm = _filmDao.LoadFilms();
            return listFilm;
        }

        /// <summary>
        /// Get list film by TheaterId
        /// </summary>
        /// <param name="theaterId"></param>
        /// <returns>List of Film</returns>
        public List<Film> GetListFilmsByTheaterId(int theaterId)
        {
            return _filmDao.GetListFilmsByTheaterId(theaterId);
        }

        /// <summary>
        /// load film by Id
        /// </summary>
        /// <returns>Film</returns>
        /// <author>hungph</author>
        public Film LoadFilmsById(int id)
        {
            var film = _filmDao.LoadFilmsById(id);
            return film;
        }

        /// <summary>
        /// Create new film
        /// </summary>
        /// <returns>success: true; fail: false</returns>
        /// <author>hungph</author>
        public bool CreateFilm(Film film)
        {
            var result = _filmDao.Add(film);
            if (result == 1)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// edit film
        /// </summary>
        /// <returns>success: true; fail: false</returns>
        /// <author>hungph</author>
        public bool EditFilm(Film film)
        {
            var result = _filmDao.Edit(film);
            if (result == 1)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// delete film
        /// </summary>
        /// <returns>success: true; fail: false</returns>
        /// <author>hungph</author>
        public bool DeleteFilm(Film film)
        {
            var result = _filmDao.Delete(film);
            if (result == 1)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// get first 7 films by favorite category id
        /// </summary>
        /// <param name="cateId"></param>
        /// <returns>list of 7 films</returns>
        /// <author>DuyHDV</author>
        public List<Film> GetFilmsByCateId(int cateId)
        {
            List<Film> films;
            try
            {
                films = _filmDao.GetFilmsByCateId(cateId);
            }
            catch (Exception e)
            {
                throw e;
            }
            return films;
        }

        ///// <summary>
        ///// get first 7 newest films
        ///// </summary>
        ///// <param name="cateId"></param>
        ///// <returns>list of 7 films</returns>
        ///// <author>DuyHDV</author>
        //public List<Film> GetNewestFilms()
        //{
        //    List<Film> films;
        //    try
        //    {
        //        films = _filmDao.GetNewestFilms();
        //    }
        //    catch (Exception e)
        //    {
        //        throw e;
        //    }
        //    return films;
        //}

        /// <summary>
        /// Load Film By Id
        /// </summary>
        /// <returns>Film</returns>
        /// <author>DuyHDV</author>
        public Film LoadFilmById(int id)
        {
            Film film = _filmDao.LoadFilmById(id);
            return film;
        }

        /// <summary>
        /// Check if film name is existed or not
        /// This function is used when Edit film
        /// </summary>
        /// <param name="film"></param>
        /// <returns>exist: true ; not exist: false</returns>
        /// <author>hungph</author>
        /// <date>3/3/2014</date>
        public bool IsFilmExistedUpdate(Film film)
        {
            return _filmDao.IsFilmExistedUpdate(film);
        }

        /// <summary>
        /// Check if film name is existed or not
        /// This function is used when Edit film
        /// </summary>
        /// <param name="film"></param>
        /// <returns>exist: true ; not exist: false</returns>
        /// <author>hungph</author>
        /// <date>3/3/2014</date>
        public bool IsFilmExistedCreate(Film film)
        {
            return _filmDao.IsFilmExistedCreate(film);
        }

        public Film GetFilmById(int id)
        {
            var film = _filmDao.GetFilmById(id);
            return film;
        }

        /// <summary>
        /// Get list film suggest for Guest
        /// </summary>
        /// <param name="listLocalStorage">list result of LocalStorage</param>
        /// <returns>List of Film</returns>
        /// <author>VuongVT</author>
        public List<Film> GetListFilmSuggestionForGuest(List<LocalStorageConcertEntity> listLocalStorage)
        {
            return _filmDao.GetListFilmSuggestionForGuest(listLocalStorage);
        }

        /// <summary>
        /// Get list film suggest for Customer
        /// </summary>
        /// <param name="listLocalStorage">list result of LocalStorage</param>
        /// <returns>List of Film</returns>
        /// <author>VuongVT</author>
        public List<Film> GetListFilmSuggestionForCustomer(List<LocalStorageConcertEntity> listLocalStorage, string userName)
        {
            return _filmDao.GetListFilmSuggestionForCustomer(listLocalStorage, userName);
        }


        /// <summary>
        /// check films to delete format type
        /// </summary>
        /// <param name="formatId"></param>
        /// <returns>true: can delete format; false: can't delete format</returns>
        /// <author>hungph</author>
        public bool CheckFilmsToDeleteFormat(int formatId)
        {
            var result = _filmDao.CountNotDeleteFilmByFormatId(formatId);
            if (result == 0)
            {
                return true;
            }
            return false;
        }

        /// <summary>
        /// Check existed comments by Film Id
        /// </summary>
        /// <param name="filmId"></param>
        /// <returns>true: existed comments; false: not existed comment of film</returns>
        /// <author>hungph</author>
        public bool CheckExistedCommentsByFilmId(int filmId)
        {
            var result = _filmDao.CountCommentByFilmId(filmId);
            if (result > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// Check existed schedules by Film Id
        /// </summary>
        /// <param name="filmId"></param>
        /// <returns>true: existed schedules; false: not existed schedule of film</returns>
        /// <author>hungph</author>
        public bool CheckExistedSchedulesByFilmId(int filmId)
        {
            var result = _filmDao.CountSchedulesByFilmId(filmId);
            if (result > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// Check the FilmId is used in Schedule and have Booked ticket or not
        /// This function is used for user Click to Edit in List Film
        /// </summary>
        /// <param name="showTimeId"></param>
        /// <returns>True: Is Using And Booked ---- False: Using And Booked </returns>
        /// <author>VuongVT</author>
        public bool IsFilmUsingAndHaveBookedTicket(int filmId)
        {
            return _filmDao.IsFilmUsingAndHaveBookedTicket(filmId);
        }

        /// <summary>
        /// Check the FilmId is used in Schedule or not
        /// This function is used for user Click to Delete in List Film
        /// </summary>
        /// <param name="showTimeId"></param>
        /// <returns>True: Is Exist ---- False: Not Exist</returns>
        /// <author>VuongVT</author>
        public bool IsFilmUsedForSchedule(int filmId)
        {
            return _filmDao.IsFilmUsedForSchedule(filmId);
        }


        /// <summary>
        /// Get all showing films
        /// This function use for showing films in Film/ListShowingFilms view
        /// </summary>
        /// <returns>List of films</returns>                       
        /// <author>DuyHDV</author>    
        public List<Film> GetAllShowingFilms()
        {
            return _filmDao.GetShowingFilms();
        }

        /// <summary>
        /// Get all showing films
        /// This function use for showing films in Film/ListShowingFilms view
        /// </summary>
        /// <returns>List of films</returns>                       
        /// <author>DuyHDV</author>    
        public List<Film> GetAllPromotionalFilms()
        {
            return _filmDao.GetPromotionalFilms();
        }

        /// <summary>
        /// Get all showing films
        /// This function use for showing films in Film/ListShowingFilms view
        /// </summary>
        /// <returns>List of films</returns>                       
        /// <author>DuyHDV</author>    
        public List<Film> GetAllComingFilms()
        {
            return _filmDao.GetComingFilms();
        }
    }
}